//
//  InfoSelectView.m
//  FindJob
//
//  Created by 233 on 16/3/3.
//  Copyright © 2016年 Lee. All rights reserved.
//

#import "InfoSelectView.h"
#import "SalaryQuaryVC.h"

#define kInfoSelectViewHeight 304

@interface InfoSelectView ()<UIPickerViewDataSource,UIPickerViewDelegate>

@property (weak, nonatomic) IBOutlet UIPickerView *pickerView;
@property (nonatomic, weak)id <InfoSelectViewDelegate>delegate;
@property (nonatomic, weak)id <InfoSelectViewDataSource>dataSource;
@property (nonatomic, assign) NSInteger numberOfCompents;

@end
@implementation InfoSelectView

- (IBAction)respondsToSureBtn:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(respondsToPressedSureBtn)]) {
        return [self.delegate respondsToPressedSureBtn];
    }
    [self removeFromSuperview];
}

- (IBAction)respondsToCanleBtn:(UIButton *)sender {
    [self removeFromSuperview];
}
#pragma mark -- public

- (instancetype)initWithDataSoure:(id<InfoSelectViewDataSource>)dataSource delegate:(id<InfoSelectViewDelegate>)delegate{
    if (self = [super init]) {
        self = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([InfoSelectView class]) owner:self options:nil][0];
        self.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height - kInfoSelectViewHeight, [UIScreen mainScreen].bounds.size.width, kInfoSelectViewHeight);
        
        self.delegate = delegate;
        self.dataSource = dataSource;
        
        self.pickerView.delegate = self;
        self.pickerView.dataSource = self;
    }
    return self;

}
- (void)reloadAllComponents{
    [self.pickerView reloadAllComponents];
}
- (void)reloadComponent:(NSInteger)component{
    [self.pickerView reloadComponent:component];
}
- (NSInteger)selectRowInComponet:(NSInteger)componet{
   return [self.pickerView selectedRowInComponent:componet];
}

#pragma mark -- UIPickerViewDataSource
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    if ([self.dataSource respondsToSelector:@selector(numberOfCompentsInSelectView:)]) {
      self.numberOfCompents = [self.dataSource numberOfCompentsInSelectView:self];
      return self.numberOfCompents;
    }
    return 0;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    if ([self.dataSource respondsToSelector:@selector(infoSelectView:numberOfRowsInCompent:)]) {
        return [self.dataSource infoSelectView:self numberOfRowsInCompent:component];
    }
    return 0;
}
#pragma mark -- UIPickerViewDelegate

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if ([self.delegate respondsToSelector:@selector(infoSelectView:titleForRow:forComponent:)]) {
        return [self.delegate infoSelectView:self titleForRow:row forComponent:component];
    }
    return @"";
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    if ([self.delegate respondsToSelector:@selector(infoSelectView:didSelectRow:inComponent:)]) {
        return [self.delegate infoSelectView:self didSelectRow:row inComponent:component];
    }
}

@end
